///\todo restore this
#if 0
#include <buola/gui/x11/auto.h>

#include <buola/gui/x11/cx11exposehelper.h>
#include <buola/gui/cwindow.h>
#include <buola/gui/cphysicalwindow.h>
#include <buola/image/csurface.h>
#include <buola/image/cgc.h>
#include <buola/gui/x11/cdoublebuffer.h>
#include <buola/gui/x11/cx11window.h>

namespace buola { namespace gui { namespace x11 {

CX11ExposeHelper::CX11ExposeHelper(CX11Window *pWindow,img::EGCCaps pGCCaps)
    :   mWindow(pWindow)
    ,   mDoubleBufferValid(false)
    ,   mGCCaps(pGCCaps)
{
}

CX11ExposeHelper::~CX11ExposeHelper()
{
}

void CX11ExposeHelper::DiscardBuffer()
{
    mDoubleBuffer=nullptr;
    mDoubleBufferValid=false;
    mTripleBuffer=nullptr;
}

void CX11ExposeHelper::InvalidateBuffer()
{
    mDoubleBufferValid=false;
}

void CX11ExposeHelper::ValidateBuffer()
{
    mDoubleBufferValid=true;
}

bool CX11ExposeHelper::HasValidBuffer()
{
    return mDoubleBufferValid;
}

img::CGC *CX11ExposeHelper::GetGC(const CRegion &pRegion,bool pClear)
{
    if(!mDoubleBuffer)
    {
        mDoubleBuffer=new CDoubleBuffer(mWindow);
    }

    img::CGC *lGC=mDoubleBuffer->GetGC(mGCCaps);
    ///\todo lGC->SetClipRegion(pRegion);

    if(pClear&&mWindow->GetBackColor().Valid())
    {
        lGC->SetSource(mWindow->GetBackColor());
        lGC->SetOperator(img::ECompOp::SRC);
        CRect_d lRect(pRegion.BoundingBox());
        lGC->Path().Rect(lRect.TopLeft(),lRect.Size());
        lGC->FillPath();
        lGC->SetOperator(img::ECompOp::OVER);
    }
    
    return lGC;
}

img::CGC *CX11ExposeHelper::GetGC(bool pClear)
{
    if(!mDoubleBuffer)
    {
        mDoubleBuffer=new CDoubleBuffer(mWindow);
    }
    
    img::CGC *lGC=mDoubleBuffer->GetGC(mGCCaps);
    ///\todo lGC->ResetClipRegion();
    
    if(pClear&&mWindow->GetBackColor().Valid())
    {
        lGC->SetSource(mWindow->GetBackColor());
        lGC->SetOperator(img::ECompOp::SRC);
        CRect_d lRect=mWindow->GetRect();
        lGC->Path().Rect(lRect.TopLeft(),lRect.Size());
        lGC->FillPath();
        lGC->SetOperator(img::ECompOp::OVER);
    }
    
    return lGC;
}

void CX11ExposeHelper::ReleaseGC(img::CGC *pGC)
{
    delete pGC;
}

img::CSurface *CX11ExposeHelper::GetTripleBuffer(const CRect_d &pRect)
{
    if(!mTripleBuffer)
        mTripleBuffer=new CDoubleBuffer(mWindow);
    mTripleBuffer->BitBlt(pRect.TopLeft(),pRect.Size(),mDoubleBuffer,pRect.TopLeft());
    return mTripleBuffer;
}

void CX11ExposeHelper::CommitBuffer(const CRegion &pRegion)
{
    if(pRegion.empty()) return;

    if(mTripleBuffer)
    {
        for(const CRect_i &lR : pRegion)
        {
            CRect_d lRect(lR);
            mWindow->GetPhysical()->BitBlt(lRect.TopLeft()+mWindow->GetClientRect().TopLeft()+
                    mWindow->GetPhysicalRelPos(),lRect.Size(),mTripleBuffer,lRect.TopLeft());
        }
        mTripleBuffer=nullptr;
    }
    else if(mDoubleBuffer)
    {
        for(const CRect_i &lR : pRegion)
        {
            CRect_d lRect(lR);
            mWindow->GetPhysical()->BitBlt(lRect.TopLeft()+mWindow->GetPhysicalRelPos(),
                    lRect.Size(),mDoubleBuffer,lRect.TopLeft()-
                    mWindow->GetClientRect().TopLeft());
        }
    }
    else
    {
        //double buffer has been discarded somewhere in the way.
        //refresh window
        mWindow->Refresh();
    }
}

void CX11ExposeHelper::CommitToTripleBuffer(img::CSurface *pTB,const CRect_d &pRect)
{
    if(pRect.w()<=0||pRect.h()<=0) return;
    if(!mDoubleBuffer) return;

    for(const CRect_i &lR : mWindow->GetClientVisibleRegion())
    {
        CRect_d lRect(lR);
        pTB->BitBlt(lRect.TopLeft()-pRect.TopLeft(),lRect.Size(),mDoubleBuffer,lRect.TopLeft()-
                mWindow->GetClientRect().TopLeft()-mWindow->GetPhysicalRelPos());
    }
}

void CX11ExposeHelper::Scroll(const CPoint_d &pPoint,const CSize_d &pSize,
                                    const CPoint_d &pSrcOrigin)
{
    //TODO:this is a hack until we know what to do when not the whole area is really scrolled
    if(!mTripleBuffer)
        mTripleBuffer=new CDoubleBuffer(mWindow);
    mTripleBuffer->BitBlt(CPoint_d(0,0),mWindow->GetClientRect().Size(),mDoubleBuffer.get(),CPoint_d(0,0));

#if 0
    swap(mDoubleBuffer,mTripleBuffer);
    if(!mDoubleBuffer)
        mDoubleBuffer=new CDoubleBuffer(mWindow);
#endif
    mDoubleBuffer->BitBlt(pPoint,pSize,mTripleBuffer.get(),pSrcOrigin);
    mTripleBuffer=nullptr;
}

/*namespace x11*/ } /*namespace gui*/ } /*namespace buola*/ }
#endif